/**
 * 多功能按钮
 */
Vue.component('choose-dir', {
    template: `<div class="choose_dir_pop">
                <van-popup class="van_pop" round closeable v-cloak :close-on-click-overlay="false" v-model="showFilepath">
                    <div class="search_list">
                        <div class="file_title">选择文件夹</div>
                        <div class="List_wrappers" >
                            <div class="fileBox" @click="fileListBtn(item)" v-for="item in filePathList">
                                <template v-if="item.pathName == '最近打开'">
                                    <div class="file_name_h">
                                        <div class="file_name_h_img"><img :src="firstImg" alt=""></div>
                                        <div class="file_name_text">{{item.pathName}}</div>
                                    </div>
                                </template>
                                <template v-else>
                                    <div class="file_name_h">
                                        <div class="file_name_h_img"><img :src="twoImg" alt=""></div>
                                        <div class="file_name_text">{{item.pathName}}</div>
                                    </div>
                                </template>
                            </div>
                        </div>
                    </div>
                </van-popup>
            </div>`,
    data() {
        return {
            showFilepath: false,
            filePathList: [],
            firstImg: '../../../image/fileYellow.png',
            twoImg: "../../../image/fileBlack.png"
        }
    },
    props: {
        showPop: {
            type: Boolean,
            default: false
        },
        yrDir: {
            type: Boolean,
            default: true
        }
    },
    watch: {
    },
    computed: {
    },
    created() {
        if(!this.yrDir) {
            this.firstImg = '../image/fileYellow.png'
            this.twoImg = '../image/fileBlack.png'
        }
    },
    mounted() {
        this.init()
    },
    methods: {
        init() {
            // let path1 = sessionStorage.getItem("path1")
            // path1 = '/storage/emulated/0/DingTalk'
            // this.filePathList = [{
            //     id: 0,
            //     userId: '0',
            //     orgId: '0',
            //     pathName: '最近打开',
            //     pathValue: '',
            //     sortOrder: null,
            //     createTime: '2025-08-20 16:04:28'
            // }
            // ,{
            //     id: 1,
            //     userId: '0',
            //     orgId: '0',
            //     pathName: path1,
            //     pathValue: '',
            //     sortOrder: null,
            //     createTime: '2025-08-20 16:04:28'
            // }];
            // return

            const userId = sessionStorage.getItem("userId");
            const orgId = sessionStorage.getItem("unitId")
            iscp_port = sessionStorage.getItem("iscp_port") || "";
            let data = {
                "orgId": orgId,
                "userId": userId,
                "timestamp": new Date().getTime() + ""
            };
            data = JSON.stringify(data)
            let sign = sm3(data);
            let AuthenticationSession = sessionStorage.getItem("Authentication");
            var URL
            $.ajax({
                url: localUrlLink + iscp_port + "/tjAiAssistant/defaultPath/searchDefaultPathList",
                type: "post",
                async: false, //是否同步，false表示同步请求
                dataType: "json",
                data: data,
                headers: {
                    "Content-Type": "application/json;charset=UTF-8",
                    Authentication: AuthenticationSession,
                    sign: sign
                },
                success: (res, txt, xhr) => {
                    console.log(xhr.getResponseHeader("sign"),8989+"sign")

                    if (sm3(res.resultValueStr) == xhr.getResponseHeader("sign")) {
                        let Authentication = xhr.getResponseHeader("Authentication")
                        if (res.code == 200) {
                            if (Authentication) {
                                sessionStorage.setItem("Authentication", Authentication);
                                 this.filePathList = [{
                                        id: '0',
                                        userId: '0',
                                        orgId: '0',
                                        pathName: '最近打开',
                                        pathValue: '',
                                        sortOrder: null,
                                        createTime: '2025-08-20 16:04:28'
                                    },
                                    ...res.resultValue
                                ];

                            }
                        } else {
                            mui.toast(res.resultValue, {
                                duration: '1000',
                                type: 'div'
                            })
                        }
                    } else {
                        mui.toast('完整性校验失败', {
                            duration: '1000',
                            type: 'div'
                        })
                    }
                },
                error: (e) => {
                    mui.toast('请求异常,请稍后再试', {
                        duration: '1000',
                        type: 'div'
                    })
                },
            });
        },
        fileListBtn(item) {
            this.closePop()
            this.$emit('choose-dir-upload', item)
        },
        closePop() {
            this.showFilepath = false
        }
    }
});